<template>
  <t-dialog  header="评审列表" top="5%" :confirmBtn="null" :visible.sync="visible" :onClose="closeDialog"
            :closeOnOverlayClick="false"
            width="80%">

    <div style="height: 65vh">
      <div class="query-form-inline">
        <h2 style="color: #000000">{{ projectName }}</h2>
      </div>
      <div class="query-form-inline">
        <h3>评审业务类型：{{ reviewType | filterByDict(dict.type.ggxq_review_type) }}</h3>
      </div>
      <div v-if="reviewType !== '1'" class="query-form-inline">
        <h3>专家组评审意见表：<span v-if="!expertLeader">未设置组长</span><span v-else>
          <span v-if="psYjsFilesNow.length<=0">未提交</span>
           <a v-else class="t-button-link" target="_blank"  :href="psYjsFilesNow[0].url" >
                        {{psYjsFilesNow[0].name}}
                      </a>
        </span></h3>
      </div>
      <t-table
        rowKey="id"
        :data="data"
        :columns="columns"
        hover
        :loading="dataLoading"
      >
        <template #[`experts.sysUser.nickName`]="{ row }">
          <t-badge v-if="row.teamLeader==='1' && !['1'].includes(reviewType)" count="组长" :offset="[-10, -6]">
            {{ row.experts.sysUser.nickName }}
          </t-badge>
          <template v-else>
            {{ row.experts.sysUser.nickName }}
          </template>
        </template>
        <template #score="{row}">
          {{ row.reviewStatus === '1' ? row.score : '' }}
        </template>
        <template #reviewStatus="{row}">
          <t-tag theme="success" variant="light" v-if="row.reviewStatus==='1'">
            已提交
          </t-tag>
          <t-tag v-else-if="row.reviewStatus === '0'" theme="warning" variant="light">暂存</t-tag>
          <t-tag theme="danger" variant="light" v-else>
            未提交
          </t-tag>
        </template>
        <template #[`experts.sysUser.duty`]="{ row }">
          <div v-if="['99999',''].includes(row.experts.sysUser?.profTit)">
            {{ row.experts.sysUser?.duty }}
          </div>
          <div v-else>
            {{ row.experts.sysUser?.duty }}/{{ row.experts.sysUser?.profTit | filterByDict(dict.type.prof_tit) }}
          </div>
        </template>
        <template #projectApproval="{row}">
          <t-tag theme="success" variant="light" v-if="row.projectApproval==='1'">
            是
          </t-tag>
          <t-tag theme="danger" variant="light" v-else-if="row.projectApproval==='0'">
            否
          </t-tag>
          <t-tag theme="warning" variant="light" v-else-if="row.projectApproval==='2'">
            需要复议
          </t-tag>
          <t-tag theme="warning" variant="light" v-else>
            未提交
          </t-tag>
<!--          <t-tag v-if="row.projectApproval"-->
<!--                  :theme="handleTheme(row.projectApproval, dict.type.kjxm_ys_review_status)" variant="light">-->
<!--            {{ row.projectApproval | filterByDict(dict.type.kjxm_ys_review_status) }}-->
<!--          </t-tag>-->
<!--          <t-tag  v-else theme="warning" variant="light">未提交-->
<!--          </t-tag>-->

        </template>
        <template #recommendType="{row}">
          <t-tag theme="danger" variant="light" v-if="row.recommendType==='1'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="success" variant="light" v-else-if="row.recommendType==='2'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="success" variant="light" v-else-if="row.recommendType==='3'">
            {{ row.recommendType | filterByDict(dict.type.recommend_type) }}
          </t-tag>
          <t-tag theme="warning" v-else variant="light">
            未提交
          </t-tag>
        </template>
        <template #[`experts.sysUser.education`]="{ row }">
          {{
            row.experts.sysUser?.education | filterByDict(dict.type.education)
          }}/{{ row.experts.sysUser?.degree | filterByDict(dict.type.degree) }}
        </template>
<!--        <template #[`experts.sysUser.degree`]="{ row }">-->
<!--          {{ row.sysUser?.degree | filterByDict(dict.type.degree) }}-->
<!--        </template>-->
        <template #op="{row}">
          <t-button
                    variant="text" class="t-button-link"
                    @click="dialog.header='专家评审';dialog.editOpen=false;dialog.row=row;dialog.open_approve_info=true">
            <t-icon name="info-circle" slot="icon"/>
            详情
          </t-button>
          <!--      <t-button theme="danger" @click="backSubmit(row)" v-if="row.reviewStatus==='1'"-->
          <!--                 variant="text" class="t-button-link">-->
          <!--        <t-icon name="edit-1" slot="icon"/>-->
          <!--        退回-->
          <!--      </t-button>-->
          <t-button v-if="$store.state.user.roles.includes('kjcspy') || $store.state.user.roles.includes('admin')"
                    @click="dialog.header='专家评审';dialog.editOpen=true;dialog.row=row;dialog.open_approve_info=true"
                    variant="text" class="t-button-link">
            <t-icon name="edit-1" slot="icon"/>
            编辑
          </t-button>
          <t-button  @click="dialog.header=`${projectName}-${row.experts.sysUser.nickName}-专家评审短信催办`;dialog.objId = row.experts.sysUser.id;dialog.open_send_msg=true" v-if="row.reviewStatus!=='1'"
                     variant="text" class="t-button-link">
            <t-icon name="cloud" slot="icon"/>
            短信催办
          </t-button>

        </template>
      </t-table>
      <approve-info @reload="getList()" :editOpen="dialog.editOpen" :drawerVisibleOpen="true" :expertEditOpen="false"
                    :header="dialog.header" :row="dialog.row" :visible.sync="dialog.open_approve_info"
                    v-if="dialog.open_approve_info"></approve-info>
      <send-msg :header="dialog.header" :obj-id="dialog.objId" :visible.sync="dialog.open_send_msg"
                v-if="dialog.open_send_msg"></send-msg>
    </div>

  </t-dialog>
</template>

<script>
import ApproveInfo from "../../../zjk/review/components/ggxq-approve-info.vue";
import SendMsg from "../../../common/system/components/send-msg.vue";
import {getFilesByUserId} from "@/api/common";


export default {
  name: "project-review-list",
  dicts: ["prof_tit", "duty", 'recommend_type', 'ggxq_review_type', "education","degree", "kjxm_ys_review_status"],
  components: {
    // EditExpertReview,
    ApproveInfo,
    SendMsg
  },
  props: ["objId", "teamId", "reviewType", "projectName", "expertLeader", "rowId"],
  data() {
    return {
      dialog: {
        objId: 0,
        teamId: 0,
        open: false,
        editOpen: false,
        open_approve_info: false,
        open_send_msg: false
      },
      visible: true,
      data: [],
      columns: [
        {
          colKey: "experts.sysUser.nickName",
          title: "专家姓名",
          align: "center"
        },
        {
          colKey: "experts.sysUser.dept.deptName",
          title: "所在单位",
          align: "center"
        },
        {colKey: 'experts.sysUser.duty', title: '职务/职称', align: "center"},
        // {colKey: 'experts.profTit', title: '职称',align: "center"},
        {colKey: 'experts.sysUser.majorName', title: '专业', align: "center"},
        {colKey: 'experts.sysUser.majorNowName', title: '现从事专业', align: "center"},
        {
          colKey: "experts.sysUser.education",
          title: "学历/学位",
          align: "center",
        },
        {
          colKey: "sort",
          title: "在本组中的排序",
          align: "center",
        },
        // {
        //   colKey: "experts.sysUser.degree",
        //   title: "学位",
        //   align: "center",
        //   ellipsis: true
        // },
        // {colKey: 'score', title: '评审分数', align: "center"},
        // {colKey: 'projectApproval', title: '是否通过',align: "center"},
        {colKey: 'projectApproval', title: '是否推荐', align: "center"},
        {colKey: 'reviewStatus', title: '评审状态', align: "center"},

        {
          colKey: "op",
          title: "操作",
          align: "center"
        },
      ],
      dataLoading: false,
      reviewStandard: {
        score: 100,
        name: "",
        reviewItems: []
      },
      psYjsFilesNow: []
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler(val) {
        if (val) {
          this.getList();
        }
      }
    }
  },
  created() {
    // this.$api.ggxq.review.teamGet(this.teamId).then(response => {
    //   if (['1'].includes(this.reviewType)) {
    //     this.$api.ggxq.review.indexGet(response.data.indexId).then(res => {
    //       this.reviewStandard = res.data;
    //     }).catch((e) => {
    //       this.$message.error(e.toString());
    //     });
    //   }
    // }).catch((e) => {
    //   this.$message.error(e.toString());
    // });
    this.getTeamExpertLeaderFile();
  },
  methods: {
    getTeamExpertLeaderFile() {
      // 获取当前组长的评审意见表附件
      if(this.expertLeader){
        getFilesByUserId(this.rowId, this.expertLeader.id).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.psYjsFilesNow = files.dgAndYsPsYjs || [];
          // if (dgAndYsPsYjsFilesNow.length > 0) {
          //   window.open(dgAndYsPsYjsFilesNow[dgAndYsPsYjsFilesNow.length - 1].url, '_blank')
          // } else {
          //   this.$message.error(`${this.expertLeader.nickName}-还未提交评审意见表`);
          // }
        }).catch(e => {
          this.$message.error(e.toString())
        })
      }

    },
    backSubmit(row) {
      const confirmDia = this.$dialog.confirm({
        header: "专家评审提示",
        body: `是否确认退回？`,
        theme: "warning",
        onConfirm: ({e}) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.ggxq.review.teamExpertsInfoUpdate({
            reviewStatus: "0",
            id: row.id
          }).then(response => {
            this.$message.success('提交成功');
            this.getList();
            // this.$emit("reload");
            // this.$emit("update:visible", false);
            confirmDia.destroy();
          }).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
      })
    },
    getList() {
      this.dataLoading = true;
      this.$api.ggxq.review.projectExpertsInfoByReviewTypeForReview({
        planId: this.objId,
        reviewType: this.reviewType,
        teamId: this.teamId,
      }).then(response => {
        this.data = response.data || [];
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
